﻿@using QLNS
@{
    ViewBag.Title = "Update";
    Layout = "~/Views/Shared/_Home.cshtml";
    PhongBan dt = ViewBag.phongban;
    
    

    // List root Dept
    List<SelectListItem> listRootDept = new List<SelectListItem>();


    List<PhongBan> root = QLNS.Models.PhongBanModels.GetDSPhongBan(0);
    if (root.Count > 0)
    {


        //Cap 1 la Don vi       
        foreach (var r in root)
        {
            SelectListItem itemr = new SelectListItem();
            itemr.Text = r.TenPhongBan;
            itemr.Value = r.ID.ToString();
            //if (dt.IDParent == r.ID)
            //{
            //    itemr.Selected = true;
            //}
            listRootDept.Add(itemr);
            List<PhongBan> root1 = QLNS.Models.PhongBanModels.GetDSPhongBan(r.ID);
            if (root1.Count > 0)
            {
                foreach (var r1 in root1)
                {
                    SelectListItem itemr1 = new SelectListItem();
                    itemr1.Text = r1.TenPhongBan;
                    itemr1.Value = r1.ID.ToString();
                    //itemr1.Selected = true;
                    //if (dt.IDParent == r1.ID)
                    //{
                    //    itemr1.Selected = true;
                    //}
                    listRootDept.Add(itemr1); 
                    List<PhongBan> root2 = QLNS.Models.PhongBanModels.GetDSPhongBan(r1.ID);
                    if (root2.Count > 0)
                    {
                        foreach (var r2 in root2)
                        {
                            SelectListItem itemr2 = new SelectListItem();
                            itemr2.Text = r2.TenPhongBan;
                            itemr2.Value = r2.ID.ToString();
                            //if (dt.IDParent == r2.ID)
                            //{
                            //    itemr2.Selected = true;
                            //}
                            listRootDept.Add(itemr2); 
                            List<PhongBan> root3 = QLNS.Models.PhongBanModels.GetDSPhongBan(r2.ID);
                            if (root3.Count > 0)
                            {
                                foreach (var r3 in root3)
                                {
                                    SelectListItem itemr3 = new SelectListItem();
                                    itemr3.Text = r3.TenPhongBan;
                                    itemr3.Value = r3.ID.ToString();
                                    //if (dt.IDParent == r3.ID)
                                    //{
                                    //    itemr3.Selected = true;
                                    //}
                                    listRootDept.Add(itemr3);
                                    List<PhongBan> root4 = QLNS.Models.PhongBanModels.GetDSPhongBan(r3.ID);
                                    if (root4.Count > 0)
                                    {
                                        foreach (var r4 in root4)
                                        {
                                            SelectListItem itemr4 = new SelectListItem();
                                            itemr4.Text = r4.TenPhongBan;
                                            itemr4.Value = r4.ID.ToString();
                                            //if (dt.IDParent == r4.ID)
                                            //{
                                            //    itemr4.Selected = true;
                                            //}
                                            listRootDept.Add(itemr4);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
    }
    }
}


<h2>Chuyển công tác</h2>
@using (Html.BeginForm("Update", "ChaDept", FormMethod.Post))
 { 
   
    <table width="500" border="1">
 
  
  <tr>
    <td>Chọn:</td>
    <td>@Html.DropDownList("ListPhongBan", listRootDept)</td>
  </tr>

</table>

        <input id="botton" type="Submit" value="Lưu" class="btnSave"/>
 }


